//
//  SRHomeworkFinishHeaderView.m
//  StoryShow
//
//  Created by CyonLeuMBP on 2017/7/26.
//  Copyright © 2017年 qudiandu.cn. All rights reserved.
//

#import "SRHomeworkFinishHeaderView.h"
#import <NSDate+DateToDisplayString.h>

@interface SRHomeworkFinishHeaderView ()

//@property (weak, nonatomic) IBOutlet UIView *borderView;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *lessonLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *scoreImageView;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
//@property (weak, nonatomic) IBOutlet UIView *coverView;
//@property (weak, nonatomic) IBOutlet UIButton *deleteButton;
//@property (weak, nonatomic) IBOutlet UIButton *doHomeworkButton;

@property (strong, nonatomic) SRWorkListItemModel *model;

@end

@implementation SRHomeworkFinishHeaderView

- (void)awakeFromNib {
    [super awakeFromNib];
        // Initialization code
    
    FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
    
    self.backgroundColor = [UIColor colorWithHex:0xeae0d6];
    
    self.lessonLabel.textColor = css.color_1;
    self.lessonLabel.font = css.fontOfH3;
    
    self.descLabel.textColor = css.color_1;
    self.descLabel.font = css.fontOfH5;
    
    self.timeLabel.textColor = css.color_1;
    self.timeLabel.font = css.fontOfH7;
    
    self.scoreLabel.textColor = css.color_4;
    self.scoreLabel.font = css.fontOfH5;
}

- (void)updateCellInfo:(SRWorkListItemModel *)model {
    if (!model) {
        return;
    }
    
    self.model = model;
    self.lessonLabel.text = model.title;
    self.descLabel.text = model.unit;
    
    [self.iconImageView fz_setImageWithDefaultPlaceholderWithURL:[NSURL URLWithString:model.page_url] placeholderSize:CGSizeZero];
    
    if (self.userType == SRSchoolClassUserTypeTeacher) {
//        self.timeLabel.text = [NSString stringWithFormat:@"完成度：%lu/%lu", (unsigned long)[self.model.cur_num integerValue], [self.model.limit_num integerValue]];
        NSInteger curNum = MAX(0, [self.model.cur_num integerValue]);
        NSInteger limitNum = MAX(curNum, [self.model.limit_num integerValue]);
        self.timeLabel.text = [NSString stringWithFormat:@"完成度：%lu/%lu", (unsigned long)curNum, limitNum];

        self.scoreLabel.hidden = YES;
        self.scoreImageView.hidden = YES;
    } else {
        if ([model.finishArray count] > 0) {
            SRWorkListItemModel *showModel = [model.finishArray firstObject];
            NSString *timeString = [NSDate dateToDisplayStringForTimeInterval:[showModel.create_time longLongValue]];
            
            self.timeLabel.text = [NSString stringWithFormat:@"完成时间：%@", timeString];

        }
//        if ([model.finishArray count] > 0) {
//                //已完成
//            SRWorkListItemModel *showModel = [model.finishArray firstObject];
            NSInteger score = [model.score integerValue];
            if (score > 0) {
                self.scoreImageView.hidden = NO;
                self.scoreLabel.hidden = NO;
                self.scoreLabel.text = [NSString stringWithFormat:@"%ld", (long)score ];
                if (score > 60) {
                    self.scoreImageView.image = [UIImage imageNamed:@"pass"];
                } else {
                    self.scoreImageView.image = [UIImage imageNamed:@"unpass"];
                }
            } else {
                self.scoreImageView.hidden = YES;
                self.scoreLabel.hidden = YES;
            }
//        }
    }
    
}

@end
